﻿<extend name="Public/base"/>
<block name="body">	
	<div class="space-custom"></div>
	<!-- breadcrumb start -->
	<div class="breadcrumb-area">
		<div class="container">
			<ol class="breadcrumb">
                <li><a href="#"><i class="fa fa-home"></i></a></li>
                <li><a href="#">Shop</a></li>
                <li class="active">购物车</li>
			</ol>			
		</div>
	</div>
	<!-- breadcrumb end -->
	<!-- cart-main-area start -->
	<div class="cart-main-area cartbody">
		<div class="container">
			<div class="row">
				<div class="col-md-12 col-sm-12 col-xs-12">
					<form action="#">				
						<div class="table-content table-responsive">
							<table>
								<thead>
									<tr>
										<th class="product-thumbnail">图片</th>
										<th class="product-thumbnail">商品</th>
										<th class="product-thumbnail">属性</th>
										<th class="product-name">单价</th>
										<th class="product-name">价格</th>
										<th class="product-price">数量</th>
										<th class="product-remove">操作</th>
									</tr>
								</thead>
								<tbody>
								    <foreach name="res" item="v">
									<tr class="shoptr"> 
										<td class="product-thumbnail"><a href="#"><img src="__ROOT__/Uploads/{$v.pic}" alt="" /></a></td>
										<td class="product-name"><a href="#">{$v.title}</a></td>
										<td class="product-name"><a href="#">{$v.vname}</a></td>
										<td class="product-price">￥<span>{$v.price}</span></td>
										<td class="product-price">￥<span class="amount">{$v.alprice}</span></td>
										<td class="product-quantity">
										<input type="hidden"  value="{$v.id}" class="shoppid">
										<input type="hidden"  value="{$v.price}" class="much">
										<input class="count" type="number" value="{$v.count}" /></td>
										<td class="product-remove del"><a href="#"><i class="fa fa-times"></i></a><input type="hidden"  value="{$v.id}" class="inputid"></td>
									</tr>
									</foreach>
								</tbody>
							</table>
						</div>
						<div class="row">
							<div class="col-md-9 col-sm-7 col-xs-12">
								<div class="buttons-cart">
									<input type="submit" value="Update Cart" />
									<a href="#">Continue Shopping</a>
								</div>
								<div class="coupon">
									<h3>Coupon</h3>
									<p>Enter your coupon code if you have one.</p>
									<input type="text" placeholder="Coupon code" />
									<input type="submit" value="Apply Coupon" />
								</div>
							</div>
							<div class="col-md-3 col-sm-5 col-xs-12">
								<div class="cart_totals">
									<h2>&nbsp;购&nbsp;物&nbsp;车&nbsp;结&nbsp;算&nbsp;</h2>
									<table>
										<tbody>
											<tr class="order-total">
												<th>数量</th>
												<td><span class="acount">{$res[0]['allcount']}</span></td>
											</tr>
											<tr class="order-total">
												<th>总计</th>
												<td>
													<strong>￥<span class="apcount">{$res[0]['allprice']}</span></strong>
												</td>
											</tr>											
										</tbody>
									</table>
									<div class="wc-proceed-to-checkout">
										<a href="{:U('order?uid='.$res[0]['uid'])}">确认订单</a>
									</div>
								</div>
							</div>
						</div>
					</form>	
				</div>
			</div>
		</div>
	</div>
</block>
<block name="script">
<script type="text/javascript">
    $(function(){
        $(".del").click(function(){
        	var index =$(".del").index($(this));
        	var id = $(".inputid").eq(index).val();
        	$.post("{:U(shopdel)}",{id:id},function(data){
                if(data.status==1){
                   $(".shoptr").eq(index).remove();
                }
        	});
        });
    });

    $(function(){
    	$(".count").click(function(){
    		var index =$(".count").index($(this));
    		var count = $(".count").eq(index).val();
    		var id = $(".shoppid").eq(index).val();
    		var much = $(".much").eq(index).val();
    		var price = count*much;
    		$(".amount").eq(index).text(price);
    		var sumprice = 0;
    		for(var a=0;a<$(".amount").length;a++){
    			var zongjia = $(".amount").eq(a).text();
    			sumprice +=Number(zongjia);
    		}
    		//console.log(sumprice);
    		var sumcount = 0;
            for(var a=0;a<$(".count").length;a++){
            	var shuliang = $(".count").eq(a).val();
            	sumcount +=Number(shuliang); 
            }
            console.log(sumcount);
            $(".acount").text(shuliang);
    		$(".apcount").text(sumprice);
    		$.post("{:U(shopupd)}",{count:count,id:id},function(data){
    		});
    	});
    });
</script>
</block>